#include <stdio.h>


#define     X   3
#define     Y   2
#define     Z   4

void matrix_multiply(int *m1, int *m2, int *r, int x, int y, int z);


int main()
{
    int     matrix1[X*Y];
    int     matrix2[Y*Z];
    int     result[X*Z];

    int row, colum;
    printf("Please input matrix first:\n");
    for (row = 0; row < X * Y; row += 1)

            scanf("%d", &matrix1[row]);

    printf("Please input matrix second:\n");
    for (row = 0; row < Y * Z; row++)

            scanf("%d", &matrix2[row]);

    matrix_multiply(matrix1, matrix2, result, X, Y, Z);

    printf("The result matrix is :\n");
    for (row = 0; row < X; row++)
    {
        for (colum = 0; colum < Z; colum++ )
                printf("%d  ", result[row * Z + colum]);
        printf("\n");
    }

    return 0;
}


void matrix_multiply(int *m1, int *m2, int *r, int x, int y, int z)
{
    register int    *m1p, *m2p;
    register int    k;
    int             row, colum;

    for (row = 0; row < x; row++) {
        for(colum = 0; colum < z; colum++) {
            m1p = m1 + row * y;
            m2p = m2 + colum;

            *r = 0;
            for (k = 0; k < y; k++) {
                *r += *m1p * *m2p;
                m1p += 1;
                m2p += z;
            }
            r++;
        }
    }
}
